package com.sgcc.sx.pmos.e_sx_order.presenter;

import android.text.TextUtils;

import com.blankj.utilcode.util.ToastUtils;
import com.sgcc.sx.pmos.common.base.BasePresenter;
import com.sgcc.sx.pmos.common.bean.BaseResponse;
import com.sgcc.sx.pmos.common.http.HttpInterConst;
import com.sgcc.sx.pmos.common.http.HttpRequestUtils;
import com.sgcc.sx.pmos.common.http.MvpNetCallback;
import com.sgcc.sx.pmos.common.utils.ListPageUtil;
import com.sgcc.sx.pmos.e_sx_order.bean.IndentBean;
import com.sgcc.sx.pmos.e_sx_order.bean.SupplementContractBean;
import com.sgcc.sx.pmos.e_sx_order.contract.ContractContract;
import com.sgcc.sx.pmos.e_sx_order.contract.SupplementContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class SupplementContractPresenter extends
        BasePresenter<SupplementContract.View> implements SupplementContract.Presenter {

    @Override
    public void getSupplementContractList(String relationId, boolean isLoading) {

        Map<String, Object> params = new HashMap<>();
        params.put("_t", System.currentTimeMillis());
        params.put("flag", "1");//1已确认,0未确认（查看补充协议选1，补充协议确认0）
        params.put("relationId", relationId);//订单ID
        HttpRequestUtils.getInstance().request(params, HttpInterConst.QUERY_SUPPLEMENT_CONTRACT,
                new MvpNetCallback<SupplementContractBean>(getView(), isLoading) {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        super.onError(call, e, id);
                        // 失败回调 判断界面是否销毁
                        if (!isViewAttached()) {
                            return;
                        }
                        getView().queryFailed();
                    }

                    @Override
                    public void onResponse(SupplementContractBean response, int id) {
                        super.onResponse(response, id);
                        if (!isViewAttached()) {
                            return;
                        }
                        if (null != response) {
                            if (null != response.getData())
                                getView().querySuccess(response.getData());
                            else {
                                if (!TextUtils.isEmpty(response.getMsg())) {
                                    ToastUtils.showShort(response.getMsg());
                                }
                                getView().queryFailed();
                            }
                        }
                    }
                });


    }
}